package models

import (
	"github.com/astaxie/beego/orm"
	"encoding/json"
	"github.com/astaxie/beego"
)

type PqSlTestItem struct {
	Id int
	PqSlTestLibraryId int
	Body string
	Analysis string
	Score int
	Note string
	State int
	BaseModel
}

func (this *PqSlTestItem) SaveQuestion(id interface{}){
	slave := GetSlaveDb()
	master := GetMasterDb()
	//var item PqSlTestItem
	//slave.QueryTable("pq_sl_test_item").Filter("id",id).One(&item)
	var questions []orm.Params
	slave.QueryTable("pq_sl_test_item").Filter("pq_sl_test_library_id",id).Filter("state__gt",-1).Values(&questions)
	storeJson,_ := json.Marshal(&questions)

	_,err := master.QueryTable("pq_sl_test_item_material").Filter("id",id).Update(orm.Params{
		"question_data" : string(storeJson),
	})
	beego.Error(err)
}